package com.example.yupao.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Title: MyBatisPlusConfig
 * @Package com.example.yupao.config
 * @Date 2024/3/17 9:52
 * @description: MP 分页查询拦截器
 *
 * @Author LittleNight
 */

@Configuration
@MapperScan("com.example.yupao.mapper")
public class MyBatisPlusConfig {

    // 添加分页拦截器, 注入为一个bean
    @Bean
    public MybatisPlusInterceptor mpInterceptor() {
        // 定义 mp 拦截器
        MybatisPlusInterceptor mpInterceptor = new MybatisPlusInterceptor();
        // 添加具体的拦截器, 指定针对 mysql 数据库
        // 如果有多个插件, 记得分页是最后添加
        PaginationInnerInterceptor pageInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        // 设置分页的上限
        pageInterceptor.setMaxLimit(1000L);
        // 添加分页拦截器
        mpInterceptor.addInnerInterceptor(pageInterceptor);
        return mpInterceptor;
    }
}
